/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */
#pragma once

#include <Config.h>
#include <lib3d/node/Node.h>
#include <noise/hard/Channel.h>
#include <animate/Soul.h>
#include <CompilerFeatures.h>

#include <memory>

namespace liba {
namespace lib3d {
namespace node {

class SoundSource :
	public Node,
	public animate::Soul
{
	NODE_DEFINITION(SoundSource)
public:
	static const Atom play_command_name;
	static const Atom pend_command_name;
	static const Atom stop_command_name;
	static const Atom node_name;

	SoundSource( const Atom & name, Node * parent );
	SoundSource(const SoundSource & other);
	virtual SoundSource * Clone() LIBA_OVERRIDE;

	virtual void LifeCycle(time_float delta_time) LIBA_OVERRIDE;
protected:
	virtual bool on_attribute( xml::Provider * prov, const std::string & name, const std::string & value ) LIBA_OVERRIDE;
	virtual bool on_end_node( xml::Provider * prov) LIBA_OVERRIDE;
private:
	void update_position(double delta_time);
	std::auto_ptr<noise::hard::Channel> channel;
	Vector last_pos;
//	double volume;
	::filesystem::String sound_name;
	Atom channel_type;
	double min_distance;
	double max_distance;
	bool loop;

	properties::Command<> playCommand;
	void executePlayCommand();
	properties::Command<> stopCommand;
	void executeStopCommand();
};

} // node
} // namespace lib3d
} // namespace liba
